This code is a test suite that uses various functions to list different resources (url maps, target proxies, global forwards, backend buckets) from a Google Cloud project, and asserts that each list is non-empty. The test suite uses functions such as listUrlMaps
, listTargetProxies
, listGlobalForwards
, and listBackendBuckets
to retrieve the lists of resources and logs the results to the console.
npm run import -- "test list url map"
var assert = require('assert');
var importer = require('../Core');
var {
listUrlMaps,
listTargetProxies,
listGlobalForwards,
listBackendBuckets
} = importer.import("list google bucket url map");
var project = 'spahaha-ea443';
var map = 'web-map';
var proxy = 'web-map-target-proxy-5';
describe('listing subdomains from load balancer', () => {
it('should list buckets maps', () => {
return listUrlMaps(project)
.then(items => {
console.log(items[Object.keys(items)[0]].hostRules);
console.log(items[Object.keys(items)[0]].pathMatchers);
console.log(items[Object.keys(items)[0]].pathMatchers[0].pathRules);
assert(Object.keys(items).length > 0, 'should have a url mapper');
return listTargetProxies(
project,
map);
})
.then(proxies => {
console.log(proxies);
assert(proxies.length > 0, 'should have a proxy');
return listGlobalForwards(
project,
proxy);
})
.then(rules => {
console.log(rules);
assert(Object.keys(rules).length > 0, 'should have a rule');
return listBackendBuckets(project);
})
.then(buckets => {
console.log(buckets);
assert(Object.keys(buckets).length > 0, 'should have a bucket');
});
})
})
const assert = require('assert');
const { listUrlMaps, listTargetProxies, listGlobalForwards, listBackendBuckets } = require('../Core');
describe('listing subdomains from load balancer', () => {
const project ='spahaha-ea443';
const map = 'web-map';
const proxy = 'web-map-target-proxy-5';
it('should list buckets maps', async () => {
// Get list of URL maps
const urlMaps = await listUrlMaps(project);
if (!urlMaps || Object.keys(urlMaps).length === 0) {
throw new Error('No URL maps found');
}
const urlMap = urlMaps[Object.keys(urlMaps)[0]];
console.log('URL Map Host Rules:', urlMap.hostRules);
console.log('URL Map Path Matchers:', urlMap.pathMatchers);
console.log('Path Matcher Path Rules:', urlMap.pathMatchers[0].pathRules);
// Get list of target proxies
const proxies = await listTargetProxies(project, map);
assert(proxies.length > 0,'should have a proxy');
console.log('Target Proxies:', proxies);
// Get list of global forwards
const rules = await listGlobalForwards(project, proxy);
assert(Object.keys(rules).length > 0,'should have a rule');
console.log('Global Forwards:', rules);
// Get list of backend buckets
const buckets = await listBackendBuckets(project);
assert(Object.keys(buckets).length > 0,'should have a bucket');
console.log('Backend Buckets:', buckets);
});
});
Code Breakdown
Dependencies and Imports
assert
module is imported for testing assertions.importer
module is required from ../Core
.importer.import('list google bucket url map')
:
listUrlMaps
listTargetProxies
listGlobalForwards
listBackendBuckets
Variables
project
: a string representing the project ID, set to 'spahaha-ea443'
.map
: a string representing the map ID, set to 'web-map'
.proxy
: a string representing the proxy ID, set to 'web-map-target-proxy-5'
.Test Suite
describe
function, with the title 'listing subdomains from load balancer'
.it
function, with the title 'should list buckets maps'
.then
blocks, each of which:
assert
.Functions Called
listUrlMaps(project)
: lists url maps for a given project.listTargetProxies(project, map)
: lists target proxies for a given project and map.listGlobalForwards(project, proxy)
: lists global forwards for a given project and proxy.listBackendBuckets(project)
: lists backend buckets for a given project.Assertions
assert(Object.keys(items).length > 0,'should have a url mapper')
: asserts that the list of url maps is non-empty.assert(proxies.length > 0,'should have a proxy')
: asserts that the list of target proxies is non-empty.assert(Object.keys(rules).length > 0,'should have a rule')
: asserts that the list of global forwards is non-empty.assert(Object.keys(buckets).length > 0,'should have a bucket')
: asserts that the list of backend buckets is non-empty.